package org.swingplus.core.scanner;

import org.swingplus.core.annotation.Style;
import org.swingplus.core.annotation.layout.Layout;
import org.swingplus.core.annotation.widget.Widget;
import org.swingplus.core.factory.AbstractAutowireBeanFactory;
import org.swingplus.core.util.AnnoManageUtil;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public class ComponentScan {


    /**
     * 向容器创建扫描到的注解的bean,判断是否构造注入还是setter注入
     * @param clazz
     */
    public static Map<Class,Class[]> scan(String packageName,Class<?> clazz){
        Map<Class,Class[]> map=new HashMap<>();
//        List<Object> instance=new ArrayList<>();
        @SuppressWarnings("rawtypes")
		Class[] clazzs=new Class[]{Layout.class,Style.class,Widget.class};
        for (Class cls:clazzs){
        	Set<Class<?>> classesList = AnnoManageUtil.getTypesAnnotatedWith("",cls);
        	for (Class class1 : classesList) {
        		if(AnnoManageUtil.existAutowiredConstructors(class1)) {
                    //构造注入
                    AbstractAutowireBeanFactory.constructorSingletonObjectsClass.add(class1);
                }else {
            		//set注入
            		AbstractAutowireBeanFactory.fieldsSingletonObjectsClass.add(class1);
            	}
			}
        	
//            List<Object> objs=AnnoManageUtil.createBeanByAnnotationsType(packageName,cls);
            List<Object> objs= null;
//            for (Object obj : objs) {
//            	if(AnnoManageUtil.existAutowiredConstructors(obj.getClass())) {
//            		//构造注入
//            		AbstractAutowireBeanFactory.constructorSingletonObjects.put(obj.getClass().getSimpleName(),obj);
//            	}else {
//            		//set注入
//            		AbstractAutowireBeanFactory.fieldsSingletonObjects.put(obj.getClass().getSimpleName(),obj);
//            	}
//			}
            map.put(cls,clazzs);
        }

        return map;
    }

}
